<template>
	<view class="contents" :style="'height:'+screenHeight+'px;'">
		<view class="bodys">
			<view class="none" v-if="show">
				<view class="coent">
					<u-empty text="您已提交过满意度评价" mode="list" icon-size="200">
					</u-empty>
				</view>
			</view>
			<view class="conent" v-else>
				<view class="header">
					<span>满意度调查问卷</span>
				</view>
				<view class="" style="padding: 10rpx;">
					<span>&emsp;我们很荣幸能够给您提供服务,也十分感谢您对我们的信任,"以病人为中心"是我们一贯的服务宗旨,为此我们恳请您对我们的工作多提宝贵意见,以帮助我们不断提高服务水准,力求至臻至善。请在您认为符合实际情况的选项后括号内打"√"。非常满意10分,满意8分,一般6分,不满意0分。谢谢！</span>
				</view>
				<view class="neiorng">
					<view class="datalist" v-for="(item,index) in datalist" :key="index">
						<view class="list">
							<span style="color: red;">*&nbsp;</span>
							<span style="font-weight: bold;">{{item.ProTempCode}}.&nbsp;</span>
							<span>{{item.ProTemContent}}</span>
						</view>
						<!-- @tap="ssss(index)" -->
						<view class="listb">
							<u-radio-group v-model="wjtx[index].value">
								<u-radio v-for="(itema, indexa) in wjtx[index].lists" @change="radioGroupChange"
									:key="indexa" :name="itema.name">
									{{itema.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view class="jianyi">
						<view style="margin-bottom: 10rpx;">欢迎您向我们的服务还有其他意见和建议。</view>
						<u-input v-model="jianyival" border type="textarea" />
					</view>

					<view class="jianyi">
						<view style="margin-bottom: 10rpx;">&emsp;如果您愿意，我们希望您能留下姓名和联络方式,以便我们联系您,听取您的意见或传送我院健康服务信息。
						</view>
						<u-field v-model="name" label="姓名" placeholder="请填写姓名">
						</u-field>
						<u-field v-model="occupation" label="职业" placeholder="请填写职业">
						</u-field>
						<u-field v-model="phone" label="电话" placeholder="请填写电话">

						</u-field>
						<view style="margin-bottom: 10rpx;">谢谢您的配合与帮助</view>
					</view>

					<view style="width: 100%;display: flex;justify-content: center;padding:40rpx;">
						<view class="submit">
							<u-button type="primary" @click="submit">提交</u-button>
						</view>
					</view>
				</view>

			</view>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				occupation: '',
				phone: '',
				show: true,
				jianyival: '',
				screenHeight: getApp().globalData.screenHeight - 44,
				datalist: '',
				wjtx: [],
				text: ''
			}
		},
		onLoad() {
			this.list()
		},
		methods: {
			ssss(index) {
				console.log("满意度问题", index)
				if (this.text != '') {
					this.wjtx[index].value = this.text
				}
				console.log("wjtx", this.wjtx)
			},
			pinkProDetails() {
			 console.log(this.wjtx)
			 console.log(this.datalist)
				let temp3={
					prodetail:''
					
				}
				let temp=[]
				
				// let temp = `{"prodetail":[`
				for (let i = 0; i < this.wjtx.length; i++) {
					
				let le
				switch(this.wjtx[i].value)
				{
					case '非常满意':le=10;break
					case '满意':le=8;break
					case '一般':le=6;break
					case '不满意':le=0;break
				}
					
					temp.push({
						ProTempId: this.datalist[i].ProTempId,
						PF: le
					});
					
					
					
				
					
				}
				console.log(temp)
				temp3.prodetail=temp
				// temp = temp + `]}`

			return JSON.stringify(temp3)
				
			},
			submit() {
				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				let sum = 0
				let item = this.wjtx
				console.log(this.wjtx)
				for (let i = 0; i < item.length; i++) {
					if (item[i].value == '非常满意') {
						sum += 10
					} else if (item[i].value == '满意') {
						sum += 8
					} else if (item[i].value == '一般') {
						sum += 6
					} else {
						sum += 0
					}
				}
				

				let ProDetails = this.pinkProDetails();
				// console.log("总分", sum)
				// return
				this.$request("ProblemTem", "Submit", {
					Content: this.jianyival,
					ProDetails:ProDetails,
					ZPF:sum,
					Name:this.name,
					Phone:this.phone,
					Work:this.occupation,
					Protype:1
					
				}).then(res => {
					console.log("提交满意度问题", res)
					if (res.code == 1) {
						this.show = true
						uni.hideLoading();

					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				});
			},
			radioChange(e) {
				console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				console.log(e);
				this.text = e
				console.log("wsat", this.wjtx)

			},
			list() {
				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				this.$request("ProblemTem", "list", {
					protype: 1


				}).then(res => {
					// console.log("满意度问题", res)
					if (res.code == 1) {
						this.datalist = res.data
						this.wjtx = []
						let objet = {
							lists: [{
									name: '非常满意',
									value: 10
								},
								{
									name: '满意',
									value: 8
								},
								{
									name: '一般',
									value: 6
								}, {
									name: '不满意',
									value: 0
								},
							],
							value: '非常满意'
						}
						for (let i = 0; i < res.data.length; i++) {
							this.wjtx[i] = JSON.parse(JSON.stringify(objet))
						}
						console.log("this.wjtx", this.wjtx)
						console.log("this.datalist", this.datalist)
						this.show = false
						uni.hideLoading();

					} else {
						this.show = true
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					this.show = true
					uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				});
			}
		}
	}
</script>

<style>
	@import './myddc.css';
</style>